package midi.patterns;

import javax.sound.midi.MidiEvent;
import javax.sound.midi.ShortMessage;
import javax.sound.midi.Track;

import midi.Pitch;

@Deprecated
public class OldMidiPattern {
	
	private OldMidiPattern next;
	private int noteNumber;
	private int velocity;
	private long length;

	public OldMidiPattern(int noteNumber, int velocity, long length){
		this.noteNumber = noteNumber;
		this.velocity = velocity;
		this.length = length;
		this.next = null;
	}
	
	public OldMidiPattern(Pitch pitch, int velocity, long length){
		this(pitch.getNoteNumber(), velocity, length);
	}
	
	public void setNext(OldMidiPattern next){
		this.next = next;
	}
	
	public OldMidiPattern getNext(){
		return next;
	}
	
	public void setNoteNumber(int noteNumber){
		this.noteNumber = noteNumber;
	}
	
	public int getNoteNumber(){
		return noteNumber;
	}
	
	public void setVelocity(int velocity){
		this.velocity = velocity;
	}
	
	public int getVelocity(){
		return velocity;
	}
	
	public void setLength(long length){
		this.length = length;
	}
	
	public long getLength(){
		return length;
	}
	
	public void addToTrack(Track track, int channel, long prevTicks){
		try{
			ShortMessage msg = new ShortMessage();
			msg.setMessage(ShortMessage.NOTE_ON, channel, noteNumber, velocity);
			
			track.add(new MidiEvent(msg, prevTicks));
			
			if (next != null){
				next.addToTrack(track, channel, prevTicks + length);
			}
			else
			{
				ShortMessage endMsg = new ShortMessage();
				endMsg.setMessage(ShortMessage.NOTE_OFF, channel, noteNumber, velocity);
				track.add(new MidiEvent(endMsg, prevTicks + length));
			}
		}
		catch (Exception e){
		}		
	}
	
}
